package tool.zyk.configuration;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import tool.zyk.connect.ServerConnectionFactory;
import tool.zyk.consts.RpcCommonConst;
import tool.zyk.consts.SerializableTypeEnum;
import tool.zyk.factory.NacosServerConnectionFactory;
import tool.zyk.spring.bean.SpringReflectExecutorFactory;

/**
 * @author feite.zyk
 * @time 2024/2/4 11:30
 * @description
 */
@Configuration
public class RpcSupportConfiguration {

    @Bean
    public SimpleRpcConfiguration simpleRpcConfiguration(
            @Qualifier("serverConnectionFactory") ServerConnectionFactory serverConnectionFactory) {
        return SimpleRpcConfiguration.builder()
                .serializableType(SerializableTypeEnum.JSON)
                .executorFactoryClassname("tool.zyk.spring.bean.SpringReflectExecutorFactory")
                .timeWaitMill(1000L)
                .serverPort(RpcCommonConst.DEFAULT_PORT)
                .applicationName("rpc-consumer")
                .serverConnectionFactory(serverConnectionFactory)
                .build();
    }

    @Bean
    public SpringReflectExecutorFactory springReflectExecutorFactory() {
        return new SpringReflectExecutorFactory();
    }

    @Bean("serverConnectionFactory")
    public ServerConnectionFactory serverConnectionFactory() {
        return new NacosServerConnectionFactory();
    }
}
